import Vue from 'vue'
import Vuex from 'vuex'
// 1. 导入包
import createPersistedState from 'vuex-persistedstate'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
    // 2. 配置为 vuex 的插件
    plugins: [createPersistedState()],
  state: {
    token:'',
    userInfo:{}
  },
  mutations: {
    updateToken(state,token) {
      state.token = token
    },
    updateuserInfo(state,payload){
      state.userInfo=payload
    }
  },
  actions: {
 async fason(context){
   const {data:res} =await axios.get('/my/userinfo')
   if(res.code !==0)return
   context.commit('updateuserInfo',res.data)
   }
  },
  modules: {
  }
})
